package site.yunnong.atvris.service.util;

import site.yunnong.atvris.common.dto.ScoreCalculateParam;

import java.time.Duration;
import java.time.LocalDateTime;

/**
 * 计算综合得分的工具类
 * @author zjh
 * @date 2021/9/9 13:56
 */
public class ScoreCalculateUtils {
    
    // 初始热度
    private static final Double INIT_SCORE = 3000d;
    
    private static final Double CLICK_POWER = 1d;
    
    private static final Double VIEW_POWER = 3d;
    
    private static final Double LIKED_POWER = 5d;
    
    private static final Double  COMMENT_POWER = 10d;
    
    private static final Double SHARE_POWER = 1d;
    
    private static final Double BASE_NUMBER = 1.1;
    
    public static Double calVideoScore(ScoreCalculateParam param) {
        // 初始热度分 + 用户交互产生的热度分 - 随时间衰减的热度分
        Double score = INIT_SCORE;
        score += CLICK_POWER * param.getClickCount();
        score += VIEW_POWER * param.getViewCount();
        score += LIKED_POWER * param.getLikedCount();
        score += COMMENT_POWER * param.getCommentCount();
        score += SHARE_POWER * param.getShareCount();
        Duration duration = Duration.between(param.getUploadTime(), LocalDateTime.now());
        score *= Math.pow(BASE_NUMBER, duration.toDays());
        return score;
    }
}
